package com.ruoyi.basedata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.WfzBaseunit;
import com.ruoyi.basedata.service.IWfzBaseunitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组织-成本中心Controller
 * 
 * @author xiefeng
 * @date 2022-12-09
 */
@RestController
@RequestMapping("/basedata/baseunit")
public class WfzBaseunitController extends BaseController
{
    @Autowired
    private IWfzBaseunitService wfzBaseunitService;

    /**
     * 查询组织-成本中心列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:baseunit:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfzBaseunit wfzBaseunit)
    {
        startPage();
        List<WfzBaseunit> list = wfzBaseunitService.selectWfzBaseunitList(wfzBaseunit);
        return getDataTable(list);
    }

    /**
     * 导出组织-成本中心列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:baseunit:export')")
    @Log(title = "组织-成本中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfzBaseunit wfzBaseunit)
    {
        List<WfzBaseunit> list = wfzBaseunitService.selectWfzBaseunitList(wfzBaseunit);
        ExcelUtil<WfzBaseunit> util = new ExcelUtil<WfzBaseunit>(WfzBaseunit.class);
        util.exportExcel(response, list, "组织-成本中心数据");
    }

    /**
     * 获取组织-成本中心详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:baseunit:query')")
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") Long fid)
    {
        return success(wfzBaseunitService.selectWfzBaseunitByFid(fid));
    }

    /**
     * 新增组织-成本中心
     */
    @PreAuthorize("@ss.hasPermi('basedata:baseunit:add')")
    @Log(title = "组织-成本中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfzBaseunit wfzBaseunit)
    {
        //获取当前的登录用户将其设置到属性中
        wfzBaseunit.setFcreator(getUsername());
        wfzBaseunit.setFlastupdateuser(getUsername());
        return toAjax(wfzBaseunitService.insertWfzBaseunit(wfzBaseunit));
    }

    /**
     * 修改组织-成本中心
     */
    @PreAuthorize("@ss.hasPermi('basedata:baseunit:edit')")
    @Log(title = "组织-成本中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfzBaseunit wfzBaseunit)
    {
        //获取当前的登录用户将其设置到属性中
        wfzBaseunit.setFlastupdateuser(getUsername());
        return toAjax(wfzBaseunitService.updateWfzBaseunit(wfzBaseunit));
    }

    /**
     * 删除组织-成本中心
     */
    @PreAuthorize("@ss.hasPermi('basedata:baseunit:remove')")
    @Log(title = "组织-成本中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable Long[] fids)
    {
        return toAjax(wfzBaseunitService.deleteWfzBaseunitByFids(fids));
    }
}
